package com.zhongjh.imageingstudy.homing;

import android.animation.TypeEvaluator;

/**
 * @author zhongjh
 * 自定义估值器,根据当前动画得出的属性值
 */
public class ImageHomingEvaluator implements TypeEvaluator<ImageHoming> {

    private ImageHoming homing;

    public ImageHomingEvaluator() {

    }

    /**
     * 如：动画进行了50%（初始值=100，结束值=200 ），那么匀速插值器计算出了当前属性值改变的百分比是50%，那么估值器则负责计算当前属性值 = 100 + 50% *（200-100） = 150.
     */
    @Override
    public ImageHoming evaluate(float fraction, ImageHoming startValue, ImageHoming endValue) {
        float x = startValue.x + fraction * (endValue.x - startValue.x);
        float y = startValue.y + fraction * (endValue.y - startValue.y);
        float scale = startValue.scale + fraction * (endValue.scale - startValue.scale);
        float rotate = startValue.rotate + fraction * (endValue.rotate - startValue.rotate);

        if (homing == null) {
            homing = new ImageHoming(x, y, scale, rotate);
        } else {
            homing.set(x, y, scale, rotate);
        }

        return homing;
    }
}
